{{- if .Values.webui.ingress.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ .Release.Name }}-webui
  labels:
{{ include "open5gs.labels.standard" . | indent 4 }}  
    app.kubernetes.io/component: webui
  annotations:
    {{- with .Values.webui.ingress.annotations }}
    {{- toYaml . | nindent 4 }}
    {{- end }}

spec:
  rules:
  {{- range .Values.webui.ingress.hosts }}
    - host: {{ .name | quote }}
      http:
        paths:
        {{- $paths := default (list "/") .paths }}
        {{- range $paths }}
          - path: {{ . }}
            backend:
              serviceName: {{ include "open5gs.fullname" $ }}-webui
              servicePort: http
        {{- end }}
  {{- end }}
  tls:
  {{- range .Values.webui.ingress.hosts }}
  {{- if .tls }}
    - hosts:
    {{- if .tlsHosts }}
      {{- range $host := .tlsHosts }}
        - {{ $host }}
      {{- end }}
    {{- else }}
        - {{ .name }}
    {{- end }}
    {{- if .tlsSecret }}
      secretName: {{ .tlsSecret }}
    {{- end }}
  {{- end }}
{{- end }}

{{- end }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-webui
  labels:
    epc-mode: webui
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: 3000
  selector:
    epc-mode: webui
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: {{ .Release.Name }}-webui 
  labels:
    epc-mode: webui
spec:
  replicas: 0
  selector:
    matchLabels:
      epc-mode: webui
  template:
    metadata:
      labels:
        epc-mode: webui
    spec:    
      containers:
      - name: webui
        imagePullPolicy: {{ .Values.webui.image.pullPolicy }}
        image: "{{ .Values.webui.image.repository }}:{{ .Values.webui.image.tag }}"      
        env:
        - name: DB_URI
          value: mongodb://app:bq9bjoMHppVHst3YfQtWvkY8oqal9ASQFiGyqE3U0NHiGkuYW2Laqc4VT5ODRYg7@ferretdb-service/open5gs?retryWrites=true&authMechanism=PLAIN
        - name: HOSTNAME
          value: '0.0.0.0'
